// Created by liusc on 2020/7/28--11:17.
<template>
    <div>
        <el-dialog
            :title="isImport?'批量导入':'批量导入'"
            :visible.sync="dialogVisible"
            width="1200px"
             :close-on-click-modal="false">

            <el-row>
                <el-col>
                    <a v-if="false" href="${path}facilityImport.xls" download="facilityImport.xls" target="_blank">下载模板</a>
                    <el-button type="primary">下载模板</el-button>
                    <br/>
                    <br/>
                    <input type="file" name="file" @change="getFile"/>
                </el-col>
            </el-row>

            <div slot="footer">
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="commit">确 定</el-button>
            </div>

        </el-dialog>
    </div>
</template>

<script>

    import {batchImport} from "../../api/public.js";

    export default {
        name: "import-info",

        data() {
            return {
                dialogVisible: false,
                isImport: false,
                importFile: null, //批时导入的文件
            }
        },

        methods: {
            show() {
                this.dialogVisible = true
            },

            getFile(event) {
                //alert(JSON.stringify(event));
                this.importFile = event.target.files[0];
            },

            commit() {
                //导入
                let formData = new FormData();
                formData.append('file', this.importFile);

                batchImport(formData).then(response => {
                        if (response.data.code == 0) {
                            this.$alert("导入成功");
                            this.dialogVisible = false
                            this.$emit('query');
                        } else {
                            this.$alert("服务端异常：" + response.message);
                        }
                    }).catch(reason => {
                        this.$alert("出错了：" + JSON.stringify(reason));
                    });
                }
            },
        }
</script>

<style scoped lang='scss'>

    @include formWrap(4);
</style>

